package com.berwin.syncer.utils;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

public class NotificationCenter {

    public static void notify(String title, String content) {
        new Thread(() -> {
            try {
                File executor = File.createTempFile("exec", ".sh");
                PrintWriter writer = new PrintWriter(executor, "UTF-8");
                writer.println("#!/bin/bash");
                writer.println();
                String cmd = String.format("/usr/bin/osascript -e 'display notification \" %s \" with title \"%s\"'", content, title);
                writer.println(cmd);
                writer.close();
                executor.setExecutable(true);

                Runtime.getRuntime().exec(String.format("%s",
                        executor.getPath()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).start();
    }

    public static void notify2(String title, String content) throws IOException {
    }

//    public static void main(String[] args) throws IOException {
////        notify("test", "content");
//        notify2("下载完成", "content");
//    }
}
